package com.yz.lzq.liwushuo.ui.modules.home;

import com.yz.lzq.liwushuo.http.HttpUtils;
import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.HomeFragmentTabLayoutBean;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/12/10.
 * Home碎片中的medel层
 */

public class HomeFragmentModel implements HomeContract.HomeModelInterface {

    /**
     * 获取tablayout中的标题
     */

  /*  @Override
    public void LoadHomeFragmentTabLayoutTittle(int gender,int genration,final OnGetNetDataListener<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>> listener) {
        */

    /**
     * get请求 请求通过@queryMap注解动态的传递多个参数
     *//*
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlContancts.HOMEFRAGMENT_TABLAYOUT_TITLE)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetroInterface retroInterface = retrofit.create(RetroInterface.class);
        //gender=1&generation=2
        Map<String, String> map = new HashMap<>();
        map.put("gender", gender+"");
        map.put("generation", genration+"");
        Call<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>> homeFragmentTabLayoutCall = retroInterface.getHomeFragmentTabLayoutBean();
        homeFragmentTabLayoutCall.enqueue(new Callback<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>>() {
            @Override
            public void onResponse(Call<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>> call, Response<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>> response) {
                if (response.isSuccess()) {
                    Log.i("tah", "onResponse: ----------->>>>>>>>>>"+response.body());
                    listener.onGetDataSucess(response.body());
                }
            }

            @Override
            public void onFailure(Call<List<HomeFragmentTabLayoutBean.DataBean.CandidatesBean>> call, Throwable t) {
                Log.i("tag", "onFailure: -------------------------->>>>>>>>>>失败！！！！！！！！！！");
                listener.onGetDataFalied(t);
            }
        });

    }
*/
    @Override
    public void LoadHomeFragmentTabLayoutTittle(int gender, int genration, final OnGetNetDataListener<HomeFragmentTabLayoutBean> listener) {
        /**
         * get请求 请求通过@queryMap注解动态的传递多个参数
         */
        //gender=1&generation=2
        Map<String, String> map = new HashMap<>();
        map.put("gender", gender + "");
        map.put("generation", genration + "");
        Observable<HomeFragmentTabLayoutBean> observable = HttpUtils.getInstance().getIApi().getHomeFragmentTabLayoutBean(map);


        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HomeFragmentTabLayoutBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.onGetDataFalied(e);
                    }

                    @Override
                    public void onNext(HomeFragmentTabLayoutBean bean) {
                        listener.onGetDataSucess(bean);

                    }
                });
    }
}
